package com.ruoyi.web.controller.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.device.DeviceInfo;
import com.ruoyi.web.domain.device.DeviceNumber;
import com.ruoyi.web.domain.device.EnvDataAnalysis;
import com.ruoyi.web.pojo.request.device.DeviceInfoRequest;
import com.ruoyi.web.service.device.DeviceInfoService;
import com.ruoyi.web.utils.v2.V2DeviceInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(value = "设备信息管理",tags = "设备信息管理")
@RestController
@RequestMapping("/device-info")
public class DeviceInfoController  extends BaseController {

    @Autowired
    private DeviceInfoService deviceInfoService;

    @ApiOperation("设备列表分页查询")
    @GetMapping("/deviceInfoPage")
    public TableDataInfo<DeviceInfo> getDeviceInfoPage(DeviceInfoRequest request){
        IPage<DeviceInfo> page = deviceInfoService.queryPage(request);
        return getDataTable(page.getRecords(),page.getTotal());
    }

    @ApiOperation("绑定设备")
    @ApiImplicitParams({  @ApiImplicitParam(name = "no",value = "二维码编号或设备号", required = true) ,
            @ApiImplicitParam(name = "type",value = "1 表示二维码编号 2 表示设备号", required = false,defaultValue = "1")})
    @PostMapping("/bindDevice")
    public AjaxResult getPage(@RequestParam String no ,@RequestParam(defaultValue = "1") Integer type){
        deviceInfoService.bindDevice(no,type);
        return AjaxResult.success();
    }


    @ApiOperation("根据设备号查询数据")
    @ApiImplicitParams({  @ApiImplicitParam(name = "no",value = "二维码编号或设备号", required = true) ,
            @ApiImplicitParam(name = "type",value = "1 表示二维码编号 2 表示设备号", required = false,defaultValue = "1")})
    @GetMapping("/getV2Device")
    public R<V2DeviceInfo> getV2Device(@RequestParam String no , @RequestParam(defaultValue = "1") Integer type){
        V2DeviceInfo v2Device = deviceInfoService.getV2Device(no, type);
        return R.ok(v2Device);
    }

    @ApiOperation("根据配置查询设备")
    @ApiImplicitParams({  @ApiImplicitParam(name = "functionCode",value = "配置code PRODUCT_FX_ID 杀虫灯设备 PRODUCT_INSECT_ID 识别设备", required = true) })
    @GetMapping("/getDeviceByCode")
    public R<List<DeviceInfo>> getV2Device(@RequestParam String functionCode){
        List<DeviceInfo> infos = deviceInfoService.getDeviceByCode(functionCode);
        return R.ok(infos);
    }

    @ApiOperation("设备数量统计")
    @GetMapping("/getDeviceNumber")
    public AjaxResult getDeviceNumber(){
        DeviceNumber deviceNumber = deviceInfoService.getDeviceNumber();
        return AjaxResult.success(deviceNumber);
    }

    @ApiOperation("得到天气分析数据")
    @PostMapping("/getEnvDataAnalysis")
    public AjaxResult getEnvDataAnalysis(){
        EnvDataAnalysis analysis = new EnvDataAnalysis();
        return AjaxResult.success(analysis);
    }
}
